<script type="text/javascript">
$(document).ready(function () {
    $('#thanhviennhom_xacnhan').hide();
    $('#thanhviennhom_xacnhan').jqxWindow({
        theme:theme,
        title: "Thêm thành viên",
        animationType:'fade',
        maxHeight: 700, 
        maxWidth: 700, 
        minHeight: 30, 
        minWidth: 250, 
        height: 400, 
        width: 500,
        resizable: false, 
        isModal: true, 
        modalOpacity: 0.3,
        closeButtonAction: 'hide',
        initContent: function () {
            $("#chonngay").jqxDateTimeInput({ theme:theme, height: 22, width: 160 });
            $('#ok').jqxButton({ theme:theme, width: '65px' });
            $('#cancel').jqxButton({ theme:theme, width: '65px' });
        }
    });
    $("#cancel").bind("click", function(){
        $("#thanhviennhom_xacnhan").jqxWindow('close');
    });
    $('#ok').bind("click", function(){
        var action =  $("#thanhviennhom_xacnhan").data("action");
        if (action == "themthanhvien"){
            //lay ma nhom
            var nhomnhac_danhsach_selectedrowindex = $("#nhomnhac_danhsach").jqxGrid('getselectedrowindex');
            var data = $('#nhomnhac_danhsach').jqxGrid('getrowdata', nhomnhac_danhsach_selectedrowindex);
            var manhom = data["ma_nhom"];
            
            //lay ma thanh vien
            var danhsach_nghesi_chuaconhom_selectedrowindex = $("#danhsach_nghesi_chuaconhom").jqxGrid('getselectedrowindex');
            var data = $('#danhsach_nghesi_chuaconhom').jqxGrid('getrowdata', danhsach_nghesi_chuaconhom_selectedrowindex);
            var mathanhvien = data["ma_nghe_si"];
            
            //lay ngay tham gia
            var ngaygianhap_unformated = $('#chonngay').jqxDateTimeInput('value');
            var date = ngaygianhap_unformated.getDate().toString();
            var month = ngaygianhap_unformated.getMonth().toString();
            var year = ngaygianhap_unformated.getFullYear().toString();
            //theo dung dinh dang cua mysql nam/thang/ngay
            var ngaythamgia = year + "-" + month + "-" + date;
        
            $("#nhomnhac_thanhvien").themThanhVien(manhom, mathanhvien, ngaythamgia);
        }
        else if (action == "xoathanhvien"){
            //lay ma nhom can cho nghe si roi nhom
            var nhomnhac_danhsach_selectedrowindex = $("#nhomnhac_danhsach").jqxGrid('getselectedrowindex');
            var data = $('#nhomnhac_danhsach').jqxGrid('getrowdata', nhomnhac_danhsach_selectedrowindex);
            var manhom = data["ma_nhom"];
            
            //lay ma thanh vien can cho roi nhom
            var danhsach_thanhvien_selectedrowindex = $("#nhomnhac_thanhvien").jqxGrid('getselectedrowindex');
            var data = $('#nhomnhac_thanhvien').jqxGrid('getrowdata', danhsach_thanhvien_selectedrowindex);
            var mathanhvien = data["ma_nghe_si"];
            
            //lay ngay roi nhom
            var ngayroinhom_unformated = $('#chonngay').jqxDateTimeInput('value');
            var date = ngayroinhom_unformated.getDate().toString();
            var month = ngayroinhom_unformated.getMonth().toString();
            var year = ngayroinhom_unformated.getFullYear().toString();
            //theo dung dinh dang cua mysql nam/thang/ngay
            var ngayroinhom = year + "-" + month + "-" + date;
            
            $("#nhomnhac_thanhvien").xoaThanhVien(manhom, mathanhvien, ngayroinhom);
        }
        $("#thanhviennhom_xacnhan").jqxWindow('close');
    });
    $.fn.setMessage = function (message){
        $("#message").text(message);
        console.log(message);
    };
    $("#thanhviennhom_xacnhan").jqxWindow('close');
});
</script>
<div id="thanhviennhom_xacnhan">
    <div>
        <img width="14" height="14" src="../../images/help.png" alt="" />
        Modal Window
    </div>
    <div>
        <?php
        include ($_SERVER["DOCUMENT_ROOT"]."/CTAN/views/NgheSi_ChuaCoNhom.php");
        ?>
        <div id="ngayxacnhan">
            <div id="message">Nhập ngày gia nhập</div><br/>
            <div id="chonngay"></div><br>
            <div style="float: left;">
                <input type="button" id="ok" value="OK" style="margin-right: 10px" />
                <input type="button" id="cancel" value="Cancel" />
            </div>
        </div>
    </div>
</div>